
/**
 * @since 1.0.0
 * @param {object} callback 调用JS-api的回调
 * @example
 * 
 * setupWebViewJavascriptBridge(fn)
 */
function setupWebViewJavascriptBridge(callback) {
    if (window.WebViewJavascriptBridge) {
        return callback(window.WebViewJavascriptBridge)
    }
    if (window.WVJBCallbacks) {
        return window.WVJBCallbacks.push(callback)
    }
    window.WVJBCallbacks = [callback]
    let WVJBIframe = document.createElement('iframe')
    WVJBIframe.style.display = 'none'
    WVJBIframe.src = 'wvjbscheme://__BRIDGE_LOADED__'
    document.documentElement.appendChild(WVJBIframe)
    setTimeout(function() {
        document.documentElement.removeChild(WVJBIframe)
    }, 0)
}

export default setupWebViewJavascriptBridge